/*
	Validate the add method fragment form.
*/
function check_mf(form) {
	var errors = "";
	
	errors += validate_name(form.name.value);
	errors += validate_description(form.description.value);
	errors += validate_orig(form.orig_method.value, form.new_method.value);
	
	if (errors != "") {
		alert("The following errors occurred:\n\n" + errors);
		return false;
	}
	
	return true;
}

/*
	Validate the add goal form.
*/
function check_goal(form) {
	var errors = "";
	
	errors += validate_name(form.name.value);
	errors += validate_description(form.description.value);
	errors += validate_goal_type(form.goal_type, form.super_goal);
	
	if (errors != "") {
		alert("The following errors occurred:\n\n" + errors);
		return false;
	}
	
	return true;
	
}

/*
	Validate name field.
*/
function validate_name(name) {
	return (name == "") ? "You did not enter a name.\n" : "";
}

/*
	Validate description field.
*/
function validate_description(description) {
	return (description == "") ? "You did not enter a description.\n" : "";
}

/*
	Validate originating methodology and new methodology fields.
*/
function validate_orig(orig_method, new_method) {	
	if ((orig_method == "Other" && new_method == "") || (orig_method != "Other" && new_method != "")) {
		return "You either chose \"Other\" for originating methodology and did not write in a new one, OR you chose something else and did not leave the new methodology field blank.\n";
	} else {
		return "";
	}
}

/*
	Validate goal type field.
*/
function validate_goal_type(goal_type, super_goal) {
	var goal_msg;
	for (var i = 0; i < goal_type.length; i++) {
		if (goal_type[i].checked) {
			if (goal_type[i].value == "Minor") {
				return validate_minor_goal(super_goal);			
			}
			return "";
		}
	}
	return "You did not select a goal type.\n";
}

function validate_minor_goal(super_goal) {
	if (super_goal.value == "None") {
		return "You selected Minor goal but did not select its corresponding super goal.\n";
		}
	return "";
}